home *** CD-ROM | disk | FTP | other *** search
- Path: castle.nando.net!news
- From: actuary@nando.net (Bill McCarthy)
- Newsgroups: comp.lang.c
- Subject: Re: Checking for Ilegal Input
- Date: 3 Mar 1996 08:49:04 GMT
- Organization: Nando.net Public Access
- Message-ID: <4hbme0$c79@castle.nando.net>
- References: <313855C7.5E86@aol.com>
- Reply-To: actuary@nando.net (Bill McCarthy)
- NNTP-Posting-Host: grail1407.nando.net
- X-Newsreader: IBM NewsReader/2 v1.2
-
- In <313855C7.5E86@aol.com>,
- gregace@aol.com writes:
-
- >I have a program where you must enter a number between 0 and 15 and check for
- >illegal input such as a number not between 0 and 15 or if a character is
- >entered.
- >
- >I used the scanf("%d",&number) to read the input.
- >
- >I check the illegal input by
- >
- >while (number<0 or number>15)
- >{ Printf("Enter a again:");
- > scanf("%d",&number);
- >}
- >
- >This check works fine accept when the user enters a character such as the
- >letter f. Does anyone know how to check illegal input that is not a number?
- >
- >Any help appreciated!
-
- Use fgets() to retrieve the number and strtod() to convert the text to
- a number. These will give you ample information for error checking the
- input.
-
- Bill McCarthy
- actuary@nando.net
- Wendell, NC USA
-
-